<template>
  <img :src="imageUrl" @click="getCaptcha" width="130" height="35"/>
</template>

<script setup>

import {onMounted, ref} from "vue";
import {getCaptchaImage} from '../api/login'
import {ElMessage} from "element-plus";

const imageUrl = ref('')

onMounted(() => {
  getCaptcha()
})

const getCaptcha = () => {
  getCaptchaImage().then(response => {
    console.log(response)
    if (response.code === 200) {
      imageUrl.value = response.data.image; // 使用 Base64 字符串作为 src
    } else {
      ElMessage.error('获取验证码失败:' + response.data.msg)
    }
  }).catch(e => {
    console.error(e)
  })
}

</script>

<style scoped>

</style>